Passed
Push — master ( 7c5f76...519897 )
by Daniel
01:25
created

classFetchRemoteData   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 16
dl 0
loc 25
rs 10
c 0
b 0
f 0
1
// Class imports
2
import classShowHideElements from './classShowHideElements';
3
import classErrorHandler from '../ErrorHandler/classErrorHandler';
4
5
/**
6
 * Class responsible for fetching the remote data
7
 */
8
export default class classFetchRemoteData {
9
  /**
10
   * The method responsible for fetching the remote data
11
   * @returns Promise Returns a promise with the data fetched. Implements a catch that hides elements and shows error message if there is an error
12
   */
13
  static fetchRemoteData() {
14
    const bilInformasjon = (<HTMLInputElement>(
15
      window.document.getElementById('bilinformasjon')
16
    )).value;
17
    const regNummer = `${process.env.API_URL}${bilInformasjon}`;
18
19
    return fetch(regNummer)
20
      .then(async (response) => {
21
        const bilResponse = await response.text();
22
        const bilData = JSON.parse(bilResponse);
23
        return bilData;
24
      })
25
      .catch(function (error) {
26
        // Hide elements if we have an error
27
        classShowHideElements.hideElements();
28
        classErrorHandler.showErrorFetchingRegNr();
29
      });
30
  }
31
}
32